<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>浅拷贝</title>
</head>
<body>
    <script>
        //拷贝 就是 复制   对象和数组
        //1. 直接赋值
        // let arr = [1,2,3,4];
        // let result = arr;

        // //测试
        // result[0] = 5000;

        // console.log(arr);
        // console.log(result);

        //2. 数组  
            let arr = [{age: 20},2,3,4];
            // 1> concat 连接数组 返回新数组
            // let result = [].concat(arr);
            // result[0].age = 30;
            // console.log(arr);
            // console.log(result);

            // 2> slice 
            // let result = arr.slice(0);
            // result[0].age = 50;
            // console.log(arr);
            // console.log(result);

            // 3> 扩展运算符
            // let result = [...arr];

            // result[0].age = 38;
            // console.log(arr);
            // console.log(result);

        //3. 对象
            //Object.assign
            let school = {
                name: '尚硅谷',
                pos: ['北京','上海','深圳','武汉']
            };
            // let result = Object.assign({}, school);
            let result = {...school};

            //修改 pos 元素的值
            result.pos[0] = 'beijing';
            
            console.log(school);
            console.log(result);

    </script>
</body>
</html>